package nacos

import (
	"fmt"
	"github.com/nacos-group/nacos-sdk-go/v2/vo"
)

// 查找健康服务
func FindHealthService(service, group_name string) (string, error) {
	// 获取 Nacos 客户端
	client, err := getNamingClient()
	if err != nil {
		return "", err
	}

	// 获取服务信息
	serv, err := client.SelectOneHealthyInstance(vo.SelectOneHealthInstanceParam{
		ServiceName: service,
		GroupName:   group_name,
	})
	if err != nil {
		return "", err
	}
	return fmt.Sprintf("%s:%d", serv.Ip, serv.Port), nil
}
